package gov.pbc.nn.kjgl.AbroadApproval.dao;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.core.orm.ParseResult;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

import gov.pbc.nn.core.bdf.IUserSelect;
import gov.pbc.nn.core.bdf.service.UserService.DefaultUserRowMapper;
import gov.pbc.nn.core.dao.PbcnnCoreJdbcDao;
@Component("userSelectA2HLDDao")
public class UserSelectA2HLDDao implements IUserSelect {
	
	@Override
	public void loadUsers(Page<IUser> page, Criteria criteria,
			Map<String, Object> params) throws Exception {
		// TODO Auto-generated method stub
		String deptId="489145101001";
		String sql = "SELECT\n"
				+ "	U.*\n"
				+ "FROM\n"
				+ "	T_USER U\n"
				+ "INNER JOIN BDF2_USER_DEPT UD ON UD.USERNAME_ = U.USERNAME_\n"
				+ "WHERE\n ";
		PbcnnCoreJdbcDao jdbc = ContextHolder.getBean(PbcnnCoreJdbcDao.BEAN_ID);
		ParseResult result = jdbc.parseCriteria(criteria, false, "U");
		if(result!=null){
			StringBuffer sb = result.getAssemblySql();
			Map<String, Object> valueMap = result.getValueMap();
			valueMap.put("deptId", deptId);
			sql += sb.toString() + " AND UD.DEPT_ID_ = ?";
			jdbc.pagingQuery(page, sql, valueMap.values().toArray(),
					new DefaultUserRowMapper());
		}
		else{
			jdbc.pagingQuery(page, sql  + "	 UD.DEPT_ID_ = ?", new Object[] { deptId }, new DefaultUserRowMapper());
			//System.out.println(page.getEntities().size());
		}
	}

}
